package com.qf.servlet;

import com.qf.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @ResponseBody: 将java对象以流的方式发送给前端
 * @RequestBody： 将前端传来的json串转为java对象
 */
@SuppressWarnings("all")
@Controller
@RequestMapping("/json")
public class JsonServlet {

    @RequestMapping("/findById")
    @ResponseBody
    public User findById(Integer id){
//        获取前端传来的参数
        System.out.println("get获得的id：" + id);
        User user = new User();
        user.setId(id);
        user.setName("普罗米修细");
        user.setBirthday(new Date());
        user.setFlag(false);
        return user;
    }

    @RequestMapping("/add")
    public  String add(@RequestBody User user){
        System.out.println(user);
        return "获取json串成功";
    }
}
